// ==UserScript==
// @name       DZ自动回复 JAE
// @namespace  http://git.oschina.net/jae/tampermonkeyScripts
// @version    0.９
// @description  DZ自动回复,刷分利器,交流QQ群:123266961
// @author         Jaeger <hj.q@qq.com>
// @include      http*
// @run-at         document-end
// ==/UserScript==

((function() {
    Random = function(start, end) {
        start--;
        return Math.ceil(Math.random() * (end - start) + start);
    }
    randomChar = function() {
        var arr = [this.Random(48, 57), Random(97, 122)];
        return String.fromCharCode(arr[this.Random(0, arr.length - 1)]);
    }
    makeStr = function(len) {
        var str = '';
        for (var i = 0; i < len; i++) {
            str += randomChar();
        }
        return str;
    }
    main = function() {
        var message = new Array();
        message[0] = '嗯，看起来还不错，谢谢楼主。';
        message[1] = '谢谢楼主分享好东西！！！';
        message[2] = '嗯，这个帖子要回复看看……';
        message[3] = '呵呵，太感谢了，真的很不错~~';
        message[4] = '呵呵，这个可以有！谢谢楼主提供。';
        message[5] = '嗯，正是我想要的……';
        message[6] = '谢谢楼主提供，支持了。';
        message[7] = '呵呵，不错，纯支持了^-^';
        message[8] = '回复看看是神马东东。';
        message[9] = '嗯，不知有木有用，试试看了……';
        message[10] = '哦，貌似很给力的样子……';
        message[11] = '嗯，先回复试试看@~@.';
        message[12] = '多谢楼主提供这个，顶一下！';
        message[13] = '虽然不用，但还是支持了！！！';
        message[14] = '非常喜欢，回复了再说，谢谢楼主！';
        message[15] = '看来不顶都不行了，谢谢楼主！';
        message[16] = '有这个啊，那先回复看看吧！';
        var flag = document.getElementById("fastpostsubmit") ? true : false;
        if (flag) {
            var messages = message[parseInt(Math.random() * 15)];
            var auto_reply_default_message = messages + makeStr(4);
            //兼容魅族论坛
            if (typeof(editdoc) != "undefined") {
                editdoc.body.innerHTML = auto_reply_default_message;
            } else {
                console.log("普通BBS" + typeof(editdoc));
                var textarea = document.getElementsByTagName("textarea")[0];
                textarea.value = auto_reply_default_message;
            }
            var submit = document.getElementById("fastpostsubmit");
            document.getElementsByName("secanswer")[0] || document.getElementsByName("seccodeverify")[0] ? '' : submit.click();
        }
    }
    var curl = location.href;
    if(!localStorage.getItem(curl))
    {
        main();
        localStorage.setItem(curl,true);
    }
})());

/*
功能：延迟批量打开帖子，配合自动回帖用于刷积分,在控制台下手动调用
参数：选择器　延迟时间（毫秒） jQuery 
coffescript源码:

###
功能：延迟批量打开帖子，配合自动回帖用于刷积分,在控制台下手动调用,所有参数均可选
参数：选择器　延迟时间（毫秒） jQuery
###
window.o=((sel=".xst",delay=10000,$=jQuery)->
       arr = (a.href for a in $(sel))
       index = arr.length - 1
       openurl = -> 
                            url = arr[index]
                            try
                                if not window.opener?.location.href then window.open(url) else window.opener.location.href = url
                            catch e
                                window.open url
                            index-- && setTimeout(openurl,delay)
                            console.log "#{delay/1000}秒后执行下一条。。。。"
        openurl()
    )

 */
window.o = (function(sel, delay, $) {
  var a, arr, index, openurl;
  if (sel == null) {
    sel = ".xst";
  }
  if (delay == null) {
    delay = 10000;
  }
  if ($ == null) {
    $ = jQuery;
  }
  arr = (function() {
    var _i, _len, _ref, _results;
    _ref = $(sel);
    _results = [];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      a = _ref[_i];
      _results.push(a.href);
    }
    return _results;
  })();
  index = arr.length - 1;
  openurl = function() {
    var e, url, _ref;
    url = arr[index];
    try {
      if (!((_ref = window.opener) != null ? _ref.location.href : void 0)) {
        window.open(url);
      } else {
        window.opener.location.href = url;
      }
    } catch (_error) {
      e = _error;
      window.open(url);
    }
    index-- && setTimeout(openurl, delay);
    return console.log("" + (delay / 1000) + "秒后执行下一条。。。。");
  };
  return openurl();
});
